package org.example.struct.array2;

import java.util.Arrays;

/**
 * @author liyishan
 * @date 2024/4/1 09:00
 * @apiNote
 */

public class Test02952MinimumAddedCoins {

    public static void main(String[] args) {
        int[] coins = {1,1,1};
        int target = 20;
        System.out.println(minimumAddedCoins(coins,target));
    }

    public static int minimumAddedCoins(int[] coins, int target) {
        Arrays.sort(coins);
        int ans = 0;
        int x = 1;
        int length = coins.length ,  index = 0;
        while (x <= target){
            if(index < length && coins[index] <= x){
                x += coins[index];
                index++;
            }else {
                x *= 2;
                ans++;
            }
        }
        return ans;
    }
}
